package com.hookgetaway.utils;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AppOpsManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import com.pl.getaway.component.AntiUninstallReceiver;
import java.io.IOException;

/* compiled from: DeviceUtil.java */
/* loaded from: classes.dex */
public class e {
    public static long A;
    public static boolean B;
    public static Boolean C;
    public static Handler a = new Handler(Looper.getMainLooper());
    public static MediaPlayer b;
    public static String c;
    public static boolean d;
    public static boolean e;
    public static boolean f;

    /* renamed from: g, reason: collision with root package name */
    public static boolean f624g;
    public static final boolean h;
    public static final boolean i;
    public static final boolean j;
    public static final boolean k;
    public static final boolean l;
    public static final boolean m;
    public static final boolean n;
    public static boolean o;
    public static boolean p;
    public static boolean q;
    public static boolean r;
    public static boolean s;
    public static boolean t;
    public static boolean u;
    public static boolean v;
    public static boolean w;
    public static boolean x;
    public static boolean y;
    public static boolean z;

    /* compiled from: DeviceUtil.java */
    /* loaded from: classes3.dex */
    public class a extends Handler {
        public a(Looper looper) {
            super(looper);
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (message.what == 102) {

            } else {
                super.handleMessage(message);
            }
        }
    }

    static {
        int i2;
        int i3;
        d = false;
        e = false;
        f = false;
        f624g = false;
        int i4 = Build.VERSION.SDK_INT;
        h = i4 < 26;
        i = i4 >= 29;
        j = i4 >= 30;
        k = i4 >= 31;
        l = i4 >= 33;
        m = i4 > 33;
        n = i4 >= 35;
        o = false;
        p = false;
        q = false;
        r = false;
        s = false;
        t = false;
        u = false;
        v = false;
        w = false;
        x = false;
        y = false;
        z = false;
        String str = Build.BRAND;
        c = str;
        if (str == null) {
            c = "";
        }
        String lowerCase = c.toLowerCase();
        c = lowerCase;
        if (!TextUtils.equals(lowerCase, "honor") && !TextUtils.equals(c, "hw") && !TextUtils.equals(c, "nova")) {
            if (!TextUtils.equals(c, "hongmi") && !TextUtils.equals(c, "redmi")) {
                if (!TextUtils.equals(c, "oppo") && !TextUtils.equals(c, "realme")) {
                    if (TextUtils.equals(c, "meizu")) {
                        c = "meizu";
                    } else if (TextUtils.equals(c, "oneplus")) {
                        c = "oneplus";
                    } else if (TextUtils.equals(c, "iqoo")) {
                        c = "vivo";
                    }
                } else {
                    c = "oppo";
                }
            } else {
                c = "xiaomi";
            }
        } else {
            if (TextUtils.equals(c, "honor")) {
                boolean y2 = y();
                t = y2;
                u = y2 && A();
                w = p() >= 38;
            }
            c = "huawei";
        }
        d = TextUtils.equals(c, "xiaomi") || RomInfoUtil.isMiui();
        p = TextUtils.equals(c, "vivo") || RomInfoUtil.isVivo();
        r = TextUtils.equals(c, "huawei") ||RomInfoUtil.isEmui();
        q = TextUtils.equals(c, "oppo") || RomInfoUtil.isOppo();
        y = TextUtils.equals(c, "meizu") || RomInfoUtil.isFlyme();
        z = TextUtils.equals(c, "oneplus") || RomInfoUtil.isOneplus();
        s = TextUtils.equals(c, "samsung");
        if (d) {
            try {
                i2 = Integer.parseInt(RomInfoUtil.getRomVersion().replaceAll("V", ""));
            } catch (NumberFormatException e2) {
                e2.printStackTrace();
                i2 = 0;
            }
            o = i2 == 11;
            e = i2 >= 11;
            f = i2 >= 14;
            f624g = i2 >= 816;
        } else if (r) {
            boolean x2 = x();
            v = x2;
            if (x2) {
                String o2 = o();
                if (!TextUtils.isEmpty(o2)) {
                    String[] split = o2.split("\\.");
                    if (split.length > 0) {
                        try {
                            i3 = Integer.parseInt(split[0]);
                        } catch (NumberFormatException unused) {
                            i3 = 0;
                        }
                        x = i3 >= 3;
                    }
                }
            } else {
                x = false;
            }
        } else {
            v = false;
            x = false;
            e = false;
            f = false;
            o = false;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("Build.VERSION.SDK_INT =");
        int i5 = Build.VERSION.SDK_INT;
        sb.append(i5);
        Log.e("DeviceUtil", sb.toString());
        B = d || (p && i5 >= 26) || x;
        C = null;
    }

    public static boolean A() {
        String l2 = l("ro.build.version.emui");
        if (TextUtils.isEmpty(l2)) {
            return false;
        }
        return l2.contains("MagicUI") || l2.contains("MagicOS");
    }

    public static boolean B(Context context) {
        if (C == null) {
            C = Boolean.valueOf((context.getResources().getConfiguration().screenLayout & 15) >= 3 || C() || z());
        }
        return C.booleanValue();
    }

    public static boolean C() {
        try {
            return ((String) Class.forName("android.os.SystemProperties").getMethod("get", String.class).invoke(null, "ro.build.characteristics")).contains("tablet");
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }

    public static /* synthetic */ void D(Context context) {
        boolean isScreenOn;
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (Build.VERSION.SDK_INT >= 20) {
            isScreenOn = powerManager.isInteractive();
        } else {
            isScreenOn = powerManager.isScreenOn();
        }
        if (isScreenOn) {
            Log.e("closeScreen", "powerScreenOn = true on post");
            E(context);
        }
    }

    public static void E(Context context) {
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (devicePolicyManager != null) {
            try {
                devicePolicyManager.lockNow();
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public static boolean F() {
        return B;
    }

    public static boolean L(Context context) {
        return (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(context)) || !i(context);
    }


    public static boolean i(Context context) {
        int i2 = Build.VERSION.SDK_INT;
        if (i2 < 19 || i2 >= 23) {
            return true;
        }
        return j(context, 24);
    }

    @TargetApi(19)
    public static boolean j(Context context, int i2) {
        if (Build.VERSION.SDK_INT < 19) {
            return false;
        }
        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class cls = Integer.TYPE;
            return ((Integer) AppOpsManager.class.getDeclaredMethod("checkOp", cls, cls, String.class).invoke(appOpsManager, Integer.valueOf(i2), Integer.valueOf(Binder.getCallingUid()), context.getPackageName())).intValue() == 0;
        } catch (Exception unused) {
            return false;
        }
    }



    public static String l(String str) {
        try {
            Class<?> cls = Class.forName("android.os.SystemProperties");
            return (String) cls.getDeclaredMethod("get", String.class).invoke(cls, str);
        } catch (Throwable unused) {
            return "";
        }
    }

    public static boolean m() {
        return false;
    }

    public static ComponentName n(Context context) {
        return new ComponentName(context, (Class<?>) AntiUninstallReceiver.class);
    }

    public static String o() {
        return r("hw_sc.build.platform.version", "");
    }

    public static int p() {
        if (!t) {
            return -1;
        }
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 31) {
            try {
                return ((Integer) us1.l("com.hihonor.android.os.Build$VERSION").d("MAGIC_SDK_INT").g()).intValue();
            } catch (vs1 unused) {
                return -1;
            }
        }
        if (i2 == 30) {
            return 31;
        }
        return i2 == 29 ? 26 : -1;
    }


    public static String r(String str, String str2) {
        try {
            Class<?> cls = Class.forName("android.os.SystemProperties");
            String str3 = (String) cls.getDeclaredMethod("get", String.class).invoke(cls, str);
            return TextUtils.isEmpty(str3) ? str2 : str3;
        } catch (Throwable th) {
            th.printStackTrace();
            return str2;
        }
    }


    public static boolean t(String str) {
        PackageInfo packageInfo;
        try {
            packageInfo = GetAwayApplication.getAppContext().getPackageManager().getPackageInfo(str, 0);
        } catch (PackageManager.NameNotFoundException e2) {
            e2.printStackTrace();
            packageInfo = null;
        }
        return packageInfo != null;
    }




//    public static void u(Activity activity) {
//        if (Build.VERSION.SDK_INT >= 23 && !((PowerManager) f.e(activity, "power")).isIgnoringBatteryOptimizations(activity.getPackageName())) {
//            Intent intent = new Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
//            intent.setData(Uri.parse("package:" + activity.getPackageName()));
//            try {
//                activity.startActivity(intent);
//                return;
//            } catch (Throwable th) {
//                th.printStackTrace();
//            }
//        }
//        Log.e("e.java","已设置【不优化电池电量】");
//    }

    public static boolean v(Context context) {
        if (Build.VERSION.SDK_INT >= 23) {
            return ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName());
        }
        return true;
    }

    public static boolean w(Context context) {
        ComponentName n2 = n(context);
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (devicePolicyManager == null) {
            return false;
        }
        return devicePolicyManager.isAdminActive(n2);
    }

    public static boolean x() {
        try {
            Class<?> cls = Class.forName("com.huawei.system.BuildEx");
            return "Harmony".equalsIgnoreCase(cls.getMethod("getOsBrand", new Class[0]).invoke(cls, new Object[0]).toString());
        } catch (Throwable unused) {
            return false;
        }
    }

    public static boolean y() {
        return Build.MANUFACTURER.equalsIgnoreCase("HONOR");
    }

    public static boolean z() {
        return t && GetAwayApplication.getAppContext().getPackageManager() != null && GetAwayApplication.getAppContext().getPackageManager().hasSystemFeature("com.hihonor.hardware.sensor.posture");
    }
}